
// TitleUI.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "BitternEvaluator.h"
#include "MainWnd.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CBitternEvaluatorApp

BEGIN_MESSAGE_MAP(CBitternEvaluatorApp, CWinApp)
	ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()


// CBitternEvaluatorApp construction

CBitternEvaluatorApp::CBitternEvaluatorApp()
{
	// support Restart Manager
	m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;

	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}


// The one and only CBitternEvaluatorApp object

CBitternEvaluatorApp theApp;
CMainWnd* g_pMainWnd = NULL;

// CBitternEvaluatorApp initialization

BOOL CBitternEvaluatorApp::InitInstance()
{
	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();


	// Create the shell manager, in case the dialog contains
	// any shell tree view or shell list view controls.
	CShellManager *pShellManager = new CShellManager;

	//show main wnd
	CPaintManagerUI::SetInstance(AfxGetInstanceHandle());
	CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() + _T("Skin"));

	CPaintManagerUI::StartHooks();

	HRESULT Hr = ::CoInitialize(NULL);
	if( FAILED(Hr) ) return FALSE;

	g_pMainWnd = new CMainWnd();
	g_pMainWnd->Create(NULL, _T(""), UI_WNDSTYLE_FRAME, 0, 0, 0, 0, 0);
	g_pMainWnd->CenterWindow();
	::ShowWindow(*g_pMainWnd, SW_SHOW);

	//CPaintManagerUI::MessageLoop();
	MSG msg = { 0 };
	while(msg.message != WM_QUIT)
	{
		if(::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if( !CPaintManagerUI::TranslateMessage(&msg) ) {
				::TranslateMessage(&msg);
				::DispatchMessage(&msg);
			}
		}
		else
		{
			g_pMainWnd->m_pm.SendNotify(NULL, _T("idle"));
			::Sleep(20);
		}
	}

	g_pMainWnd = NULL;

	::CoUninitialize();

	CPaintManagerUI::StopHooks();

	// Delete the shell manager created above.
	if (pShellManager != NULL)
	{
		delete pShellManager;
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}